//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import type {
  ChangePwdByEmailParams,
  ChangePwdParams,
  UserLoginByEmailParams,
  UserLoginParams,
  UserLoginRes,
  VerifyNewEmailParams,
} from './type'
import { AxiosResponse } from 'axios'
// 项目用户相关的请求地址
enum Auth_API {
  GET_LOGIN_CAPTCHA = '/teaching_system/auth/captcha/login/{email}',
  GET_NEWEMAIL_CAPTCHA = '/teaching_system/auth/captcha/newEmail/{email}',
  GET_OLDEMAIL_CAPTCHA = '/teaching_system/auth/captcha/oldEmail/{email}',
  GET_CHANGE_PWD_CAPTCHA = '/teaching_system/auth/captcha/pwd/{email}',
  POST_CHANGE_EMAIL = '/teaching_system/auth/change/newEmail',
  POST_CHANGE_PWD = '/teaching_system/auth/change/pwd',
  POST_CHANGE_PWD_BYEMAIL = '/teaching_system/auth/change/pwd/byEmail',
  POST_LOGIN_EMAIL = '/teaching_system/auth/login/email',
  POST_LOGIN_PWD = '/teaching_system/auth/login/pwd',
  POST_VERIFY_OLDEMAIL = '/teaching_system/auth/verify/oldEmail',
}

/**
 * 登录验证码
 * @param {string} email
 * @returns
 */
export const reqGetLoginCaptcha = (email: string) =>
  request.get<any, AxiosResponse<any>>(
    Auth_API.GET_LOGIN_CAPTCHA.replace('{email}', email),
  )

/**
 * 新邮箱验证码
 * @param {string} email
 * @returns
 */
export const reqGetNewEmailCaptcha = (email: string) =>
  request.get<any, AxiosResponse<any>>(
    Auth_API.GET_NEWEMAIL_CAPTCHA.replace('{email}', email),
  )

/**
 * 旧邮箱验证码
 * @param {string} email
 * @returns
 */
export const reqGetOldEmailCaptcha = (email: string) =>
  request.get<any, AxiosResponse<any>>(
    Auth_API.GET_OLDEMAIL_CAPTCHA.replace('{email}', email),
  )

/**
 * 密码修改邮箱验证码
 * @param {string} email
 * @returns
 */
export const reqGetChangePwdCaptcha = (email: string) =>
  request.get<any, AxiosResponse<any>>(
    Auth_API.GET_CHANGE_PWD_CAPTCHA.replace('{email}', email),
  )

/**
 * 验证并修改邮箱
 * @param {object} params 修改邮箱对象
 * @param {string} params.email 旧邮箱
 * @param {string} params.newEmail 新邮箱
 * @param {string} params.captcha 验证码
 * @returns
 */
export const reqChangeEmail = (params: VerifyNewEmailParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_CHANGE_EMAIL, params)

/**
 * 通过原密码修改密码
 * @param {object} params 修改密码对象
 * @param {string} params.username 用户名(身份对应的工号）
 * @param {string} params.password 旧密码
 * @param {string} params.newPassword 新密码
 * @returns
 */
export const reqChangePwd = (params: ChangePwdParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_CHANGE_PWD, params)

/**
 * 通过邮箱修改密码
 * @param {object} params 修改密码对象（email）
 * @param {string} params.email 邮箱
 * @param {string} params.captcha 验证码
 * @param {string} params.newPassword 新密码
 * @returns
 */
export const reqChangePwdByEmail = (params: ChangePwdByEmailParams) =>
  request.post<any, AxiosResponse<any>>(
    Auth_API.POST_CHANGE_PWD_BYEMAIL,
    params,
  )

/**
 * 用户邮箱登录
 * @param {object} params 用户邮箱登录对象
 * @param {string} params.email 登录用户邮箱
 * @param {string} params.captcha 验证码
 * @returns
 */
export const reqLoginByEmail = (params: UserLoginByEmailParams) =>
  request.post<any, AxiosResponse<UserLoginRes>>(
    Auth_API.POST_LOGIN_EMAIL,
    params,
  )

/**
 * 用户登录
 * @param {object} params 用户密码登录对象
 * @param {string} params.username 用户名(身份对应的工号）
 * @param {string} params.password 密码
 * @returns
 */
export const reqLogin = (params: UserLoginParams) =>
  request.post<any, AxiosResponse<UserLoginRes>>(
    Auth_API.POST_LOGIN_PWD,
    params,
  )

/**
 * 验证旧邮箱
 * @param {object} params 用户邮箱登录对象
 * @param {string} params.email 登录用户邮箱
 * @param {string} params.captcha 验证码
 * @returns
 */
export const reqVrifyOldEmail = (params: UserLoginByEmailParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_VERIFY_OLDEMAIL, params)
